<template>
  <div class="noisy-container" v-loading="isloading">
    <div class="header-top">
      <span class="active"><i class="el-icon-s-fold"></i>所有通知</span>
    </div>
    <div class="noisy-footer">
      <el-table :data="tableData" stripe border style="width: 100%" class="eltable">
        <el-table-column label="序号" width="120" type="index" />
        <el-table-column prop="title" label="主题" />
        <el-table-column prop="depName" label="发起部门" width="150" />
        <el-table-column prop="createUserName" label="发起人" width="150" />
        <el-table-column prop="createTime" label="发送时间" width="190" />
        <el-table-column label="操作" width="150" fixed="right">
          <template slot-scope="scope">
            <el-tooltip class="item" effect="dark" content="查看详情" placement="bottom">
              <el-button type="primary" icon="el-icon-search" circle @click="openxaingqing(scope.row)"></el-button>
            </el-tooltip>
            <el-tooltip class="item" effect="dark" content="修改" placement="bottom">
              <el-button type="primary" icon="el-icon-edit" circle @click="editnoisy(scope.row)"></el-button>
            </el-tooltip>
            <el-tooltip class="item" effect="dark" content="删除" placement="bottom">
              <el-button type="danger" icon="el-icon-delete" circle plain @click="handleDelete(scope.row.id)">
              </el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination v-if="tableData.length > 0" class="elpagi" :total="total" @size-change="getdata"
        @current-change="getdata" @prev-click="getdata" @next-click="getdata" :current-page.sync="listquery.currentPage"
        :page-sizes="[10, 20, 30, 40]" :page-size.sync="listquery.pageSize"
        layout="total,sizes, prev, pager, next, jumper" />
    </div>
  </div>
</template>
<script>
  import { getlist, del } from "@/api/notice.js";
  import { handleCofirm } from "@/utils/confirm";
  export default {
    data() {
      return {
        tableData: [],
        isloading: false,
        listquery: {
          currentPage: 1,
          pageSize: 10,
        },
      };
    },
    mounted() {
      this.getdata();
    },
    methods: {
      async getdata() {
        let res = await getlist(this.listquery);
        this.tableData = res.data.content;
        this.total = res.data.totalElements;
      },

      back() {
        this.$router.push("/noisy/index");
      },
      openxaingqing(data) {
        this.$router.push({ path: "/message/messagebox", query: { ...data } })
      },
      editnoisy(data) {

        this.$router.push({ path: "/edit/editmessage", query: { ...data } })
      },
      handleDelete(id) {
        handleCofirm("确认要删除吗？", "warning").then((res) => {
          del(id)
            .then((v) => {
              this.getdata();
              this.$notify({
                title: "成功",
                message: "删除成功",
                type: "success",
              });

            })
            .catch((error) => {
              this.$notify.error({
                title: "错误",
                message: error,
              });
            });
        });
      },
    },
  };
</script>
<style lang="scss" scoped>
  @import "../../../public/css/table.scss";

  .noisy-container {
    margin: 5px;
    background-color: #fff;

    .header-top {
      line-height: 50px;
      background-color: #f2f2f2;
      margin-bottom: 10px;

      span {
        margin-right: 10px;
        padding: 10px;
        border-radius: 5px;
        color: #4778c7;
        font-weight: 400;

        i {
          margin-right: 5px;
        }

        &:hover {
          background-color: #fff;
        }
      }

      .active {
        background-color: #fff;
      }
    }
  }
</style>